﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace BLL
{
    public class HangSanPhamBLL
    {
        public List<HangSanPham> GetAllHangSanPham()
        {
            using (var cc = new ChamCongEntities())
            {
                return cc.HangSanPhams.ToList<HangSanPham>();
            }
        }
        public HangSanPham GetHangSanPhamById(int id)
        {
            ChamCongEntities cc = new ChamCongEntities();
            return cc.HangSanPhams.Where(cd => cd.HangSPId == id).FirstOrDefault();
        }
        public void InsertHangSanPham(HangSanPham hangSanPham)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(hangSanPham).State = EntityState.Added;
                cc.SaveChanges();
            }
        }
        public void UpdateHangSanPham(HangSanPham hangSanPham)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(hangSanPham).State = EntityState.Modified;
                cc.SaveChanges();
            }

        }
        public void DeleteHangSanPham(HangSanPham hangSanPham)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(hangSanPham).State = EntityState.Deleted;
                cc.SaveChanges();
            }
        }
    }
}
